package com.wwc.business.controller;

import com.wwc.business.controller.dto.train.TrainDeleteDTO;
import com.wwc.business.controller.dto.train.TrainInsertDTO;
import com.wwc.business.controller.dto.train.TrainSelectListDTO;
import com.wwc.business.controller.dto.train.TrainUpdateDTO;
import com.wwc.business.controller.vo.TrainSelectListVO;
import com.wwc.business.service.ITrainService;
import com.wwc.common.response.CommonResponse;
import com.wwc.common.response.PageResponse;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 火车 Controller
 */
@RestController
@RequestMapping("/admin/train")
public class TrainController{
	@Resource
	private ITrainService trainService;

	/**
	 * 新增火车
	 */
	@PostMapping("/insert")
	public CommonResponse<?> insert(@Valid @RequestBody TrainInsertDTO trainInsertDTO){
		trainService.insert(trainInsertDTO);
		return new CommonResponse<>();
	}

	/**
	 * 更新火车
	 */
	@PostMapping("/update")
	public CommonResponse<?> update(@Valid @RequestBody TrainUpdateDTO trainUpdateDTO){
		trainService.update(trainUpdateDTO);
		return new CommonResponse<>();
	}

	/**
	 * 删除火车
	 */
	@PostMapping("/delete")
	public CommonResponse<?> delete(@Valid @RequestBody TrainDeleteDTO trainDeleteDTO){
		trainService.delete(trainDeleteDTO);
		return new CommonResponse<>();
	}

	/**
	 * 查询火车列表
	 */
	@GetMapping("/select-list")
	public CommonResponse<List<TrainSelectListVO>> selectList(){
		List<TrainSelectListVO> trainSelectListDTO = trainService.selectList();
		return new CommonResponse<>(trainSelectListDTO);
	}

	/**
	 * 查询火车分页列表
	 */
	@GetMapping("/select-list-page")
	public CommonResponse<PageResponse<TrainSelectListVO>> selectListPage(@Valid TrainSelectListDTO trainSelectListDTO){
		PageResponse<TrainSelectListVO> pageResponse = trainService.selectListPage(trainSelectListDTO);
		return new CommonResponse<>(pageResponse);
	}
}
